package cn.yitun.chat.yitunservercommonlib.databind.jackson;

import cn.yitun.chat.yituncommonutil.YitunDateUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.text.ParseException;
import java.util.Date;

/**
 * 
 * Description 时间格式反序列化 <br>
 * Date 2019-04-29 09:18:16<br>
 * 
 * @author yitun
 * @since 1.1
 */
public class CustomDateDeserializer extends JsonDeserializer<Date> {
	@Override
	public Date deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		Date localDate = null;
		String text = jsonParser.getText();
		if (null != text) {
			String date = YitunDateUtil.allToDateTimeMillisecond(text);
			try {
				localDate = YitunDateUtil.stringDateToDate(date, YitunDateUtil.FORMAT_DATE_TIME_MILLISECOND);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return localDate;
	}
}
